
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

import { AboutSlint, Button } from "std-widgets.slint";
export component TestCase inherits Window {

    in-out property <string> app_title: "Application";

    in-out property <string> result;

    MenuBar {
        Menu {
            title: "File";
            MenuItem {
                title: "New";
                activated => { result += self.title; debug("New"); }
            }
            MenuItem {
                title: "Open";
                activated => { debug("Open"); }
            }
            Menu {
                title: "Open Recent";
                for num in 45 : MenuItem {
                    title: "Recent " + num;
                    activated => {
                        if self.title != "Recent " + num {
                            result += "Error: invalid self.title";
                        }
                        result += self.title;
                        debug("Recent", num);
                    }
                }
            }
            MenuItem {
                title: "Save";
                activated => { debug("Save"); }
            }
            MenuSeparator {}
            if true: MenuItem {
                title: "Exit " + app_title;
                activated => {
                    app_title = "Exited";
                }
            }
            MenuSeparator {}
            MenuSeparator {}
        }
        Menu {
            title: "Edit";
            MenuItem {
                title: "Copy";
                activated => { debug("Copy"); }
            }
            MenuSeparator {}
            if true: MenuItem {
                title: "Paste";
                activated => { debug("Paste"); }
            }
            MenuSeparator {}
            MenuItem {
                title: "Disabled";
                enabled: false;
                activated => { result += self.title; }
            }
        }
    }
    vl := VerticalLayout {
        AboutSlint {}
        Button { text: "Hello"; }
    }

    out property <bool> check-geometry: vl.x == 0 && vl.y == 0 && vl.width == root.width && vl.height == root.height;

    out property <bool> test: check-geometry;
}

/*
```rust
use slint::{SharedString, platform::{Key}};
let instance = TestCase::new().unwrap();
assert!(instance.get_test());
// click on the file menu
slint_testing::send_mouse_click(&instance, 10., 10.);
// navigate using the keys to the "Open Recent" menu item
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::RightArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::UpArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::UpArrow));
assert_eq!(instance.get_result(), "");
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from("\n"));
assert_eq!(instance.get_result(), "Recent 43");

instance.set_result("".into());
slint_testing::send_mouse_click(&instance, 10., 10.);
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from("\n"));
assert_eq!(instance.get_result(), "New");

// ensure that disabled items can't activate
instance.set_result("".into());
slint_testing::send_mouse_click(&instance, 100., 10.);
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from("\n"));
assert_eq!(instance.get_result(), "");

```

```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
assert(instance.get_test());
// click on the file menu
slint_testing::send_mouse_click(&instance, 10., 10.);
// navigate using the keys to the "Open Recent" menu item
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::RightArrow);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::UpArrow);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::UpArrow);
assert_eq(instance.get_result(), "");
slint_testing::send_keyboard_string_sequence(&instance, "\n");
assert_eq(instance.get_result(), "Recent 43");

instance.set_result("");
slint_testing::send_mouse_click(&instance, 10., 10.);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow);
slint_testing::send_keyboard_string_sequence(&instance, "\n");
assert_eq(instance.get_result(), "New");

// ensure that disabled items can't activate
instance.set_result("");
slint_testing::send_mouse_click(&instance, 100., 10.);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow);
slint_testing::send_keyboard_string_sequence(&instance, "\n");
assert_eq(instance.get_result(), "");

```

```js
var instance = new slint.TestCase();
assert(instance.test);
// click on the file menu
slintlib.private_api.send_mouse_click(instance, 10., 10.);
// navigate using the keys to the "Open Recent" menu item
slintlib.private_api.send_keyboard_string_sequence(instance, "\u{F701}");
slintlib.private_api.send_keyboard_string_sequence(instance, "\u{F701}");
slintlib.private_api.send_keyboard_string_sequence(instance, "\u{F701}");
slintlib.private_api.send_keyboard_string_sequence(instance, "\u{F703}");
slintlib.private_api.send_keyboard_string_sequence(instance, "\u{F700}");
slintlib.private_api.send_keyboard_string_sequence(instance, "\u{F700}");
assert.equal(instance.result, "");
slintlib.private_api.send_keyboard_string_sequence(instance, "\n");
assert.equal(instance.result, "Recent 44");

instance.result = "";
slintlib.private_api.send_mouse_click(instance, 10., 10.);
slintlib.private_api.send_keyboard_string_sequence(instance, "\u{F701}");
slintlib.private_api.send_keyboard_string_sequence(instance, "\n");
assert.equal(instance.result, "New");

// ensure that disabled items can't activate
instance.result = "";
slintlib.private_api.send_mouse_click(instance, 100., 10.);
slintlib.private_api.send_keyboard_string_sequence(instance, "\u{F701}");
slintlib.private_api.send_keyboard_string_sequence(instance, "\u{F701}");
slintlib.private_api.send_keyboard_string_sequence(instance, "\u{F701}");
slintlib.private_api.send_keyboard_string_sequence(instance, "\n");
assert.equal(instance.result, "");

*/
